<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>~/Projects/Java/CS222/CodingChallenge/src/CoChall.java.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;CoChall.java</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Write a program that uses a method printArgs() to print each</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;String in args[] one character at a time with a space after each</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;String except for the final one.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* Create a subclass of this program that overrides printArgs() to print each</font><br>
<font color="#0000ff">&nbsp;* String in args[] one character at a time in reverse printing a space after</font><br>
<font color="#0000ff">&nbsp;* each string except for the last one.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">&nbsp;&nbsp;John Thomason</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Date: Nov 22, 2008</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;Course: CS221 Introduction to Java Programming</font><br>
<font color="#0000ff">&nbsp;* Seminar: ?</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;Assign: ?</font><br>
<font color="#0000ff">&nbsp;*/</font><br>
<br>
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;CoChall Class</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;- Description</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;CoChall {<br>
<br>
&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Application Entry Point</font><br>
<font color="#0000ff">&nbsp;&nbsp; </font><font color="#0000ff">* </font><font color="#6a5acd">@param</font><font color="#008b8b">&nbsp;args</font><font color="#0000ff">&nbsp;The command line arguments</font><br>
<font color="#0000ff">&nbsp;&nbsp; */</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;main(String[]&nbsp;args)&nbsp;{<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;CoChall&nbsp;&nbsp;&nbsp;&nbsp;cc&nbsp;&nbsp;= <font color="#a52a2a"><b>new</b></font>&nbsp;CoChall();<br>
&nbsp;&nbsp;&nbsp;&nbsp;SubCoChall scc = <font color="#a52a2a"><b>new</b></font>&nbsp;SubCoChall();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>(&nbsp;args.length &gt; <font color="#ff00ff">0</font>&nbsp;){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cc.printArgs(args);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scc.printArgs(args);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;}<font color="#0000ff">//End main()</font><br>
<br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;printArgs(String[]&nbsp;args){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;a = args.length;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(String s: args){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(<font color="#2e8b57"><b>char</b></font>&nbsp;c: s.toCharArray()){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(c);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<font color="#0000ff">//for()</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>(--a &gt; <font color="#ff00ff">0</font>)&nbsp;System.out.print(<font color="#ff00ff">&quot; &quot;</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<font color="#0000ff">//for()</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<br>
&nbsp;&nbsp;}<font color="#0000ff">//printArgs()</font><br>
<br>
}<font color="#0000ff">//End CoChall Class</font><br>
<br>
<font color="#2e8b57"><b>class</b></font>&nbsp;SubCoChall<br>
<font color="#2e8b57"><b>extends</b></font>&nbsp;CoChall {<br>
<br>
&nbsp;&nbsp;<font color="#a020f0">@Override</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;printArgs(String[]&nbsp;args){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;a = args.length;<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(String s: args){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(<font color="#2e8b57"><b>int</b></font>&nbsp;i = s.length()&nbsp;- <font color="#ff00ff">1</font>; i &gt;= <font color="#ff00ff">0</font>; i--){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.print(s.charAt(i));<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<font color="#0000ff">//for()</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>(--a &gt; <font color="#ff00ff">0</font>)&nbsp;System.out.print(<font color="#ff00ff">&quot; &quot;</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<font color="#0000ff">//for()</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<br>
&nbsp;&nbsp;}<font color="#0000ff">//printArgs()</font><br>
<br>
}<font color="#0000ff">//End SubCoChall</font><br>
</font></body>
</html>
